// 排行榜模块
import { reqGetTopList,reqGetRankingDetail } from '@/api/ranking'
const GET_TOP_LIST = "GET_TOP_LIST"
const GET_RANKING_DETAIL = "GET_RANKING_DETAIL"
const UPDATE_FREQUENCY = "UPDATE_FREQUENCY"

export default {
  namespaced:true,
  state:{
    // 排行榜类别
    categoryList:[],
    // 歌单详情
    rankingDetail:{},
    // 选中榜单的更新频率
    updateFrequency:null
  },
  actions:{
    // 获取所有榜单
    async getTopList({commit}){
      const {list} = await reqGetTopList()
      // 第一次默认显示第一个榜单
      const {playlist} = await reqGetRankingDetail(list[0].id)
      commit(GET_TOP_LIST,{list,playlist})
      commit(UPDATE_FREQUENCY,list[0].updateFrequency)
    },
    // 获取选中歌单详情动态
    async getRankingDetail({commit},id){
      const {playlist} = await reqGetRankingDetail(id)
      commit(GET_RANKING_DETAIL,playlist)
    }
  },
  mutations:{
    [GET_TOP_LIST](state,{list,playlist}){
      state.categoryList = list
      state.rankingDetail = playlist
    },
    [GET_RANKING_DETAIL](state,playlist){
      state.rankingDetail = playlist
    },
    // 选中榜单更新频率
    [UPDATE_FREQUENCY](state,updateFrequency){
      state.updateFrequency = updateFrequency
    }
  },
  getters:{

  }
}